package com.onLineCar.es.sync;

import com.godGuang.common.core.domain.Result;


import com.onLineCar.es.domain.Content;
import com.onLineCar.es.feign.PatientsData;
import com.onLineCar.es.service.EsService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author : 段敏强
 * @className : EsSync
 * @description : 描述说明该类的功能
 * @createTime : 2024/01/10 09:14
 */


/**
 * 定时任务
 */

@Component
public class EsSync {

    @Autowired
    private PatientsData patientData;

    @Autowired
    private EsService esServer;


    /**
     * 定时任务，每小时同步一次数据
     */
    @Scheduled(cron = "0/10 * * * * ?")
    public void sync(){
        // 调用远程服务获取数据
        Result<List<Content>> list = patientData.list();
        if (Result.FAIL == list.getCode()){
            throw new RuntimeException("同步数据失败");
        }
        if (Result.SUCCESS  == list.getCode()){
            esServer.esAdd(list.getData());
        }
    }


}
